import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../services/favorites_service.dart';

class FavoriteButton extends StatelessWidget {
  final String city;

  const FavoriteButton({
    super.key,
    required this.city,
  });

  @override
  Widget build(BuildContext context) {
    final favoritesService = Provider.of<FavoritesService>(context);
    final isFavorite = favoritesService.isFavorite(city);

    return IconButton(
      icon: Icon(
        isFavorite ? Icons.favorite : Icons.favorite_border,
        color: isFavorite ? Colors.red : null,
      ),
      onPressed: () {
        if (isFavorite) {
          favoritesService.removeFavorite(city);
        } else {
          favoritesService.addFavorite(city);
        }
      },
    );
  }
}
